package com.seo.service.task.impl;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.springframework.stereotype.Service;

import com.seo.function.FunctionT1R.FunctionT1;
import com.seo.function.FunctionT2R.FunctionT2;
import com.seo.function.FunctionT3R;
import com.seo.function.FunctionT4R;
import com.seo.function.FunctionT5R;


@Service("userKeywordsToolService")
public class UserKeywordsToolServiceImpl{

	public ExecutorService threadPool = Executors.newFixedThreadPool(1);

	public <T1> void async(FunctionT1<T1> func, T1 t1) {
		threadPool.execute(new Runnable() {
			@Override
			public void run() {
				func.invoke(t1);
			}
		});
	}
	
	public <T1, T2> void async(FunctionT2<T1, T2> func, T1 t1, T2 t2) {
		threadPool.execute(new Runnable() {
			@Override
			public void run() {
				func.invoke(t1, t2);
			}
		});
	}

	public <T1, T2, T3, R> void async(FunctionT3R<T1, T2, T3, R> func, T1 t1, T2 t2, T3 t3) {
		threadPool.execute(new Runnable() {
			@Override
			public void run() {
				func.invoke(t1, t2, t3);
			}
		});
	}

	public <T1, T2, T3, T4, R> void async(FunctionT4R<T1, T2, T3, T4, R> func, T1 t1, T2 t2, T3 t3, T4 t4) {
		threadPool.execute(new Runnable() {
			@Override
			public void run() {
				func.invoke(t1, t2, t3, t4);
			}
		});
	}

	public <T1, T2, T3, T4, T5, R> void async(FunctionT5R<T1, T2, T3, T4, T5, R> func, T1 t1, T2 t2, T3 t3, T4 t4,
			T5 t5) {
		threadPool.execute(new Runnable() {
			@Override
			public void run() {
				func.invoke(t1, t2, t3, t4, t5);
			}
		});
	}


	public ExecutorService getExecutorService() {
		return threadPool;
	}

}
